<?php

namespace App\Http\Controllers\Admin;


use App\Http\Model\User;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Input;

require_once 'resources/org/code/Code.class.php';
class LoginController extends CommonController
{
    //登录页面方法
    public function login()
    {   //用Input::all() 获取post表单数据
        if($input=Input::all()){

            $code= new \Code;
            $_code=$code->get();
            if(strtolower($input['code'])!=strtolower($_code)){
                //验证码验证错误，回调到当前页面
                return back()->with('msg','验证码错误');
            }
            $user=User::first();
            if($user->user_name != $input['user_name'] || $input['user_pass'] != Crypt::decrypt($user->user_pass)){
                return back()->with('msg','用户名或密码错误');
            }
            session(['user'=>$user]);
       return redirect('admin/index');
        }else{
                session(['user'=>null]);
            return view('admin.login');
        }

    }
    //验证码功能方法
    public function code()
    {
        $code= new \Code;
        $code->make();
    }

    public function quit()
    {
        session(['user'=>null]);
        return redirect('admin/login');
    }
   

}
